"""
    构建一个简单的神经网络
"""

import numpy as np
from common.functions import sigmoid_function,identity

# 初始化神经网络的参数
def init_network():
    """
        组织好网络结构，每一层网络包含：
            1. 输入
            2. 权重(W) -> 根据下一层的输出来决定形状，一般是一个二维矩阵，例如：输入为 2，输出为3，就是一个 2行3列 的矩阵
            3. 偏置(b)
    :return:    网络的结构
    """
    network = {}

    # 第 0 层的输入为: 2 个神经元，输出为 3 个神经元
    network['W1'] = np.array([[0.1,0.3,0.5],[0.2,0.4,0.6]])
    network['b1'] = np.array([0.1,0.2,0.3])

    # 第一层的输入是：3 个神经元，输出为 2 个神经元
    network['W2'] = np.array([[0.1,0.4],[0.2,0.5],[0.3,0.6]])
    network['b2'] = np.array([0.1,0.2])

    network['W3'] = np.array([[0.1,0.4],[0.2,0.5]])
    network['b3'] = np.array([0.1,0.2])

    return network

# 前向传播
def forward(network,x):
    W1,W2,W3 = network['W1'],network['W2'],network['W3']
    b1,b2,b3 = network['b1'],network['b2'],network['b3']

    a1 = np.dot(x,W1) +b1
    z1 = sigmoid_function(a1)

    a2 = np.dot(z1,W2) + b2
    z2 =sigmoid_function(a2)

    a3 = np.dot(z2,W3) + b3
    y = identity(a3)

    return y


# 测试主流程

x = np.array([[1,0.5],[2,0.5],[3,0.5]])

network = init_network()

y = forward(network,x)
print(y)